
define("register",["jquery","md5","jquery.validate","jquery.idcode"],function ($) {
    return{
        register:function () {
            $("footer").load("footer.html");
            $.idcode.setCode();
            $.validator.addMethod("ctel",function (val,ele) {
                var reg=/^[1]+\d{10}$/;
                return reg.test(val);
            },"请输入合法的手机号码");
            $("form").validate({
                rules:{
                    utel:{
                        required:true,
                        ctel:true,
                        remote:"../server/aging.php",

                    },
                    upwd:{
                        required:true,
                        rangelength:[6,20],
                    },
                    ucheck:{
                        required:true,
                    },

                },
                messages:{
                    utel:{
                        required:"必填项",
                        remote:"一个手机号码只可以注册一次",
                    },
                    upwd:{
                        required:"必填项",
                        rangelength:"密码长度在{0}-{1}",
                    },
                    ucheck:{
                        required:"请勾选此选项",
                    },

                },
                submitHandler:function () {
                    var IsBy = $.idcode.validateCode();

                    if(IsBy){
                        var data=$("form").serialize();
                        var par=parm(data);
                         par.upwd=$.md5(par.upwd);
                          $.ajax({
                            type:"post",
                            url:"../server/register.php",
                            data:par,
                        }).then(function (res) {
                            if(res.stu==1){
                                confirm("注册成功,是否登陆") ? window.location="login.html" : "";
                            }
                        })


                    }
                    else {
                        $(".yzcode").html("验证码输入错误");
                    }


                    return false;
                }
            });

            function parm(key) {
                var obj={};
                var arr=decodeURIComponent(key).split("&");
                for(var i=0,len=arr.length; i<len; i++){
                    var arr2=arr[i].split("=");
                     obj[arr2[0]]=arr2[1];
                }
                return obj;

            }



        }
    }
})